param ($RootDirectory, $excludeDir="dependencies|libs" , [switch]$FailOnFind)

[string]$matchArg = "\\($excludeDir)\\"
# get the list of projects
$projects = Get-ChildItem $RootDirectory -filter '*.csproj'  -Recurse

# find all lines with "<hintpath>" then exclude ones that don't contain dependencies or libs
[array]$BadHints = $projects | Select-String "<hintpath>" | Where-Object {! ($_.Line -match $matchArg)}
		
#Report Results
if ($BadHints)
{
  Write-Host "Excluding HintPath references for $excludeDir folder" 
	if (-not $FailOnFind)
	{
	  Write-Host "=============================================================================================="
	  $BadHints | %{ Write-Warning "Bad hintpath in file $($_.Path) Line: $($_.LineNumber) - $($_.Line.Trim())" }
	  Write-Host "=============================================================================================="
		Write-Host "$($BadHints.count) bad hintpath reference(s) found."
	}	

	if ($FailOnFind)
	{
	  Write-Host "=============================================================================================="
		$BadHints | %{ Write-host "Bad hintpath in file $($_.Path) Line: $($_.LineNumber) - $($_.Line.Trim())" -foregroundcolor red}
	  Write-Host "=============================================================================================="
		Throw "$($BadHints.count) bad hintpath reference(s) found."
	}
	
}
Write-Host "Find-BadHintPath.ps1 script completed"
#write errors to a file then read with Nant